package day29_69;

/**
 * @ClassName Solution
 * @Description 二分搜索
 * @Author clockTown
 * @Date 2021/6/7 20:49
 * @Version 1.0
 */
public class Solution {
    public int mySqrt(int x) {
        int l = 0, r = x, ans = -1;
        while (l <= r) {
            int mid = l + (r - l) / 2;
            if ((long) mid * mid <= x) {
                ans = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        return ans;
    }
}

